package mtons.cast.modules.play.ticket.strategy;

import com.alibaba.fastjson.JSON;
import mtons.cast.modules.log.Printer;
import mtons.cast.modules.play.ticket.Ticket;
import mtons.cast.modules.utils.HttpUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author langhsu
 */
public class FFCTicketStrategy extends AbstractStrategy implements Ticket {
    HttpUtils httpUtils = new HttpUtils();

    private String URL = "http://774444.cc/json/ffc.json";

    // 战绩
    private int rollbacks = 1;
    private List<String> history = new ArrayList<>();

    public String produce(boolean prevResult, String round) {
        String ret;
        // 上次亏损
//        if (!prevResult && rollbacks < 3) {
//            System.out.println("亏损, 回滚次数: " + rollbacks);
//            ret = history.get(history.size() - rollbacks);
//            System.out.println("- 使用:" + ret + "下单 -");
//            rollbacks ++;
//        } else {
//            rollbacks = 1;
//            ret = doRequest();
//
//            history.add(ret);
//        }

        if (!prevResult && rollbacks < 2) {
            rollbacks ++;
            // 返回空  歇一把
            return null;
        } else {
            rollbacks = 1;
            ret = doRequest();

            history.add(ret);
        }
        return ret;
    }

    private String doRequest() {
        String ret = null;
        try {
            String entity = httpUtils.get(URL);

            // 获取本期计划
            Object gameMultiple = JSON.parseObject(entity).get("GameMultiple");
            ret = JSON.parseObject(gameMultiple.toString()).get("num").toString();

            Printer.info("分析号码:" + ret);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ret;
    }

}
